package StringExercise;

public class StringBuilderDemo1 {
    public static void main(String[] args) {
        /*
        //StringBuilder的创建方式:
        StringBuilder builder1=new StringBuilder();//空字符串
        StringBuilder builder2=new StringBuilder("abc");
        //String和StringBuilder之间的转换
        String str1="abc";
        StringBuilder builder3=new StringBuilder(str1);//String转StringBuilder
        String str2=builder3.toString();//StringBuilder转String

         */

        String str1="好好学习java";
        StringBuilder builder1=new StringBuilder(str1);
        //append():追加内容----在末尾追加
        builder1.append(",为了找个好工作");
        System.out.println(builder1);
        //replace():替换部分内容(含头不含尾)
        builder1.replace(8,16,"，就是为了改变世界");
        System.out.println(builder1);
        //delete():删除部分内容(含头不含尾)
        builder1.delete(0,9);
        System.out.println(builder1);
        //insert():插入内容
        builder1.insert(0,"活着,");
        System.out.println(builder1);


    }
}
